package org.dochandler.test.tester;

import static org.junit.Assert.assertEquals;

import org.dochandler.service.domain.Officer;
import org.dochandler.service.domain.Rank;
import org.dochandler.service.domain.constants.Constants;
import org.dochandler.test.service.MissionReportServiceTest;
import org.dochandler.test.service.core.MissionReportServiceTestImpl;
import org.esfinge.guardian.context.AuthorizationContext;
import org.esfinge.guardian.context.WrappedObj;
import org.esfinge.guardian.exception.AuthorizationException;
import org.junit.Test;

public class MissionReader {
	
	
	/**
	 * Test of the Security Policy Id SP07
	 */
	@Test
	public void readConfidentialMissionByOfficerAboveTheCreatorTest() {
		Officer subject = new Officer();
		subject.setRank( Rank.COLONEL );
		
		Officer creator = new Officer();
		creator.setRank( Rank.LIEUTENANT );
		
		WrappedObj<Officer> w1 = AuthorizationContext.wrapAsSubjectProp(Constants.OFFICER.val(), subject);
		WrappedObj<Officer> w2 = AuthorizationContext.wrapAsSubjectProp(Constants.CREATOR.val(), creator);
		
		MissionReportServiceTest mrs = AuthorizationContext.guardObject(
																new MissionReportServiceTestImpl(), 
																w1, w2);
		
		assertEquals("Colonels should be able to read documents created by Lieutenants", mrs.readReport(), true);
		
	}
	
	
	/**
	 * Test of the Security Policy Id SP07
	 * 
	 */
	@Test(expected=AuthorizationException.class)
	public void readConfidentialMissionByOfficerBelowTheCreatorTest() {
		Officer subject = new Officer();
		subject.setRank( Rank.LIEUTENANT );
		
		Officer creator = new Officer();
		creator.setRank( Rank.COLONEL );
		
		WrappedObj<Officer> w1 = AuthorizationContext.wrapAsSubjectProp(Constants.OFFICER.val(), subject);
		WrappedObj<Officer> w2 = AuthorizationContext.wrapAsSubjectProp(Constants.CREATOR.val(), creator);
		
		MissionReportServiceTest mrs = AuthorizationContext.guardObject(
																new MissionReportServiceTestImpl(), 
																w1, w2);
		
		mrs.readReport();
		
	}

	
	
	
}